package com.ruoyi.web.controller.teaching;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.vo.PlatformTTaskInVO;
import com.ruoyi.teaching.service.PlatformTTaskService;
import com.ruoyi.teaching.utils.UniversalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王旭
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/platform/task")
@Api(tags = "platform-作业管理")
public class PlatformTTaskController {
    @Autowired
    private PlatformTTaskService platformTTaskService;

    /**
     * 查询老师自己发布的作业列表
     */
//    @PreAuthorize("@ss.hasPermi('platform:task:list')")
    @ApiOperation(value = "查询老师自己发布的作业列表", notes = "查询老师自己发布的作业列表")
    @GetMapping("/list")
    public AjaxResult list(Integer pageNum, Integer pageSize, String taskName, Integer taskCourse, Integer taskChapter, Integer taskPart)
    {
        return platformTTaskService.selectPlatformTTaskList(pageNum,pageSize,taskName,taskCourse,taskChapter,taskPart);
    }

//    /**
//     * 查询学生自己的作业列表
//     */
////    @PreAuthorize("@ss.hasPermi('platform:task:list')")
//    @ApiOperation(value = "查询学生自己的作业列表", notes = "查询学生自己的作业列表")
//    @GetMapping("/listStudent")
//    public AjaxResult listStudent()
//    {
//        return platformTTaskService.selectPlatformTTaskListStudent();
//    }

    /**
     * 获取作业详细信息
     */
//    @PreAuthorize("@ss.hasPermi('platform:task:query')")
    @ApiOperation(value = "获取作业详细信息", notes = "获取作业详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return platformTTaskService.selectPlatformTTaskById(id);
    }

    /**
     * 新增作业
     */
//    @PreAuthorize("@ss.hasPermi('platform:task:add')")
    @Log(title = "新增作业", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增作业", notes = "新增作业")
    @PostMapping
    public AjaxResult add(@RequestBody PlatformTTaskInVO platformTTaskVO)
    {
        List<String> errorMessages = new ArrayList<>(UniversalUtil.validate(platformTTaskVO.getTaskName(), 1, 20, true, "考试名称"));
        if(!CollectionUtils.isEmpty(errorMessages)){
            return AjaxResult.error(String.join(", ", errorMessages));
        }
        return platformTTaskService.insertPlatformTTask(platformTTaskVO);
    }

    /**
     * 删除作业
     */
//    @PreAuthorize("@ss.hasPermi('platform:task:remove')")
    @Log(title = "删除作业", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除作业", notes = "删除作业")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return platformTTaskService.deletePlatformTTaskByIds(ids);
    }
}

